home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Hardcore Visual Basic 5.0 (2nd Edition)
/
Hardcore Visual Basic 5.0 - Second Edition (1997)(Microsoft Press).iso
/
Code
/
Goodies
/
SYSTEM~1
/
SYSCOL~1.CTL
< prev
next >
Wrap
Text File
|
1997-06-09
|
14KB
|
424 lines
VERSION 5.00
Begin VB.UserControl SysColors
AutoRedraw = -1 'True
BorderStyle = 1 'Fixed Single
ClientHeight = 1320
ClientLeft = 0
ClientTop = 0
ClientWidth = 2040
ScaleHeight = 88
ScaleMode = 3 'Pixel
ScaleWidth = 136
ToolboxBitmap = "SysColors.ctx":0000
Begin VB.VScrollBar VScroll1
Height = 855
LargeChange = 9
Left = 240
Max = 18
TabIndex = 0
Top = 240
Width = 255
End
End
Attribute VB_Name = "SysColors"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit
'System Color Palette 1.0 - (27 Windows 4.0 System colors)
'Created by Randy Russell - June 1997
'Created using Microsoft Visual Basic 5.0
'values for clicktype property
Enum ClickTypes
SingleClick = 1
DoubleClick = 2
End Enum
'values for DefaultColor property
Enum SystemColors
[3DDKShadow] = 0
[3DFace] = 1
[3DHighlight] = 2
[3DLight] = 3
[3DShadow] = 4
ActiveBorder = 5
ActiveTitleBar = 6
ApplicationWorkspace = 7
ButtonFace = 8
ButtonShadow = 9
ButtonText = 10
Desktop = 11
GrayText = 12
Highlight = 13
HighlightText = 14
InactiveBorder = 15
InactiveCaptionText = 16
InactiveTitleBar = 17
InfoBackground = 18
InfoText = 19
MenuBar = 20
MenuText = 21
ScrollBars = 22
TitleBarText = 23
WindowBackground = 24
WindowFrame = 25
WindowText = 26
End Enum
'declare program variables
Dim SysColorNames(26) As String 'array for color names
Dim SysColors(26) As Long 'array for color values
Dim CurTop As Integer 'scroll position
Dim iColor As Integer 'default, cur selected color
Dim CurHighLight As Integer 'currently highlighted color
Dim rFlag As Boolean 'resize recursion flag
'Property Variables:
Dim MyClickType As ClickTypes 'single or double click
Dim MyBackColor As OLE_COLOR 'palette background color
Dim MyForeColor As OLE_COLOR 'palette text color
Dim SelColor As Long 'user selected color value
Dim SelColorName As String 'user selected color name
Dim MyColor As Integer 'user selected default color
'Event Declarations:
Public Event Click() 'MappingInfo=UserControl,UserControl,-1,Click
Public Event DblClick() 'MappingInfo=UserControl,UserControl,-1,DblClick
Public Event MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseDown
Public Event MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseMove
Public Event MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single) 'MappingInfo=UserControl,UserControl,-1,MouseUp
Public Event Scroll(Value As Integer) 'MappingInfo=VScroll1,VScroll1,-1,Scroll
'Default Property Values:
Const m_def_ClickType = DoubleClick 'default is double click
Const m_def_BackColor = vbButtonFace
Const m_def_ForeColor = vbButtonText
Const CellDim = 13 'size of color boxes
Const OffsetY = 16 'distance between rows
Const DefColor = 6 'default color value vbActiveTitlebar
Private Sub DrawCell(CellX As Integer, CellY As Integer, CellWidth As Integer, CellHeight As Integer, CellColor As Long)
'plot 3d square and fill with current color
UserControl.ForeColor = &H808080
UserControl.Line (CellX, CellY)-(CellX + CellWidth - 1, CellY)
UserControl.Line (CellX, CellY)-(CellX, CellY + CellHeight - 1)
UserControl.ForeColor = vbWhite
UserControl.Line (CellX, CellY + CellHeight - 1)-(CellX + CellWidth, CellY + CellHeight - 1)
UserControl.Line (CellX + CellWidth - 1, CellY)-(CellX + CellWidth - 1, CellY + CellHeight)
UserControl.ForeColor = &HC0C0C0
If UserControl.ForeColor = CellColor Then UserControl.ForeColor = &HE0E0E0
UserControl.Line (CellX + 1, CellY + CellHeight - 2)-(CellX + CellWidth - 1, CellY + CellHeight - 2)
UserControl.Line (CellX + CellWidth - 2, CellY + 1)-(CellX + CellWidth - 2, CellY + CellHeight - 1)
UserControl.ForeColor = vbBlack
UserControl.Line (CellX + 1, CellY + 1)-(CellX + 1, CellY + CellHeight - 2)
UserControl.Line (CellX + 1, CellY + 1)-(CellX + CellWidth - 2, CellY + 1)
UserControl.ForeColor = CellColor
UserControl.Line (CellX + 2, CellY + 2)-(CellX + CellWidth - 3, CellY + CellHeight - 3), , BF
End Sub
Private Sub UserControl_Initialize()
'initialize program variables
GetColorValues
CurTop = 0
rFlag = False
End Sub
Private Sub DrawSysPal(TopIndex As Integer)
'declare local variables
Dim i As Integer
Dim j As Integer
Dim px As Integer
Dim py As Integer
'clear palette and validate top row index
px = 2
py = 1
UserControl.Cls
UserControl.BackColor = MyBackColor
'set palette size
rFlag = True
UserControl.Width = 2315 'optimum so no horz scroll needed
rFlag = True
UserControl.Height = 2240 'setup for 9 visible rows spaced 16 apart + borders
VScroll1.Top = 0
VScroll1.Left = 132
VScroll1.Height = 145
VScroll1.Width = 18
If TopIndex > 18 Then TopIndex = 18
If TopIndex < 0 Then TopIndex = 0
CurTop = TopIndex
'plot the 9 visible rows
For i = TopIndex To TopIndex + 8
DrawCell px, py + 1, CellDim, CellDim, SysColors(i)
If CurHighLight = i Then
'draw a filled rect for highlight
UserControl.Line (px + CellDim + 2, py - 1)-(VScroll1.Left - 5, py + OffsetY - 2), vbHighlight, BF
UserControl.ForeColor = vbHighlightText
Else
UserControl.ForeColor = MyForeColor
End If
'position and print color name
UserControl.CurrentX = px + CellDim + 3
UserControl.CurrentY = py
UserControl.Print SysColorNames(i)
'reset position for next row
py = py + OffsetY
px = 2
Next i
'add 3d line to seperate scrollbar
i = VScroll1.Left - 2
UserControl.Line (i, 0)-(i, ScaleHeight), vb3DShadow
UserControl.Line (i + 1, 0)-(i + 1, ScaleHeight), vb3DHighlight
UserControl.Refresh
End Sub
Private Sub UserControl_MouseDown(Button As Integer, Shift As Integer, X As Single, Y As Single)
Dim icell As Integer
Dim NewColor As Integer
'if right button clicked then cancel
If Button = 2 Then
SelColorName = ""
'Hide
Else
'determine selection
icell = Int(Y / OffsetY)
NewColor = CurTop + icell
'if clicked the same color again then set selection and hide
If NewColor = iColor And MyClickType = 1 Then
SelColor = SysColors(NewColor)
SelColorName = SysColorNames(NewColor)
'Hide
Else
'else reset highlight and repaint
iColor = NewColor
CurHighLight = iColor
DrawSysPal CurTop
If MyClickType = 1 Then
SelColor = SysColors(NewColor)
SelColorName = SysColorNames(NewColor)
End If
End If
End If
RaiseEvent MouseDown(Button, Shift, X, Y)
End Sub
Private Sub UserControl_InitProperties()
Set Font = Ambient.Font
UserControl.Enabled = True
'set current default color
MyColor = DefColor
CurHighLight = MyColor
SelColor = SysColors(MyColor)
SelColorName = SysColorNames(MyColor)
MyBackColor = m_def_BackColor
MyForeColor = m_def_ForeColor
MyClickType = m_def_ClickType
'draw palette
DrawSysPal CurTop
End Sub
Private Sub UserControl_Resize()
If rFlag Then
rFlag = False
Else
DrawSysPal CurTop
End If
End Sub
Private Sub VScroll1_Change()
'pass current top row value and repaint
DrawSysPal VScroll1.Value
End Sub
Private Sub UserControl_DblClick()
'set selection and pass event
SelColor = SysColors(iColor)
SelColorName = SysColorNames(iColor)
RaiseEvent DblClick
End Sub
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=UserControl,UserControl,-1,Enabled
Public Property Get Enabled() As Boolean
Attribute Enabled.VB_Description = "Returns/sets a value that determines whether an object can respond to user-generated events."
Enabled = UserControl.Enabled
End Property
Public Property Let Enabled(ByVal New_Enabled As Boolean)
UserControl.Enabled() = New_Enabled
PropertyChanged "Enabled"
End Property
'WARNING! DO NOT REMOVE OR MODIFY THE FOLLOWING COMMENTED LINES!
'MappingInfo=UserControl,UserControl,-1,Font
Public Property Get Font() As Font
Attribute Font.VB_Description = "Returns a Font object."
Attribute Font.VB_UserMemId = -512
Set Font = UserControl.Font
End Property
Public Property Set Font(ByVal New_Font As Font)
Set UserControl.Font = New_Font
PropertyChanged "Font"
End Property
Private Sub UserControl_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseMove(Button, Shift, X, Y)
End Sub
Private Sub UserControl_MouseUp(Button As Integer, Shift As Integer, X As Single, Y As Single)
RaiseEvent MouseUp(Button, Shift, X, Y)
RaiseEvent Click
End Sub
Private Sub VScroll1_Scroll()
RaiseEvent Scroll(VScroll1.Value)
End Sub
'Load property values from storage
Private Sub UserControl_ReadProperties(PropBag As PropertyBag)
UserControl.Enabled = PropBag.ReadProperty("Enabled", True)
Set Font = PropBag.ReadProperty("Font", Ambient.Font)
MyColor = PropBag.ReadProperty("DefaultColor", DefColor)
MyBackColor = PropBag.ReadProperty("BackColor", m_def_BackColor)
MyForeColor = PropBag.ReadProperty("ForeColor", m_def_ForeColor)
MyClickType = PropBag.ReadProperty("ClickType", m_def_ClickType)
'set current default color
CurHighLight = MyColor
SelColor = SysColors(MyColor)
SelColorName = SysColorNames(MyColor)
'draw palette
DrawSysPal CurTop
End Sub
'Write property values to storage
Private Sub UserControl_WriteProperties(PropBag As PropertyBag)
Call PropBag.WriteProperty("Enabled", UserControl.Enabled, True)
Call PropBag.WriteProperty("Font", Font, Ambient.Font)
Call PropBag.WriteProperty("DefaultColor", MyColor, DefColor)
Call PropBag.WriteProperty("BackColor", MyBackColor, m_def_BackColor)
Call PropBag.WriteProperty("ForeColor", MyForeColor, m_def_ForeColor)
Call PropBag.WriteProperty("ClickType", MyClickType, m_def_ClickType)
End Sub
Public Sub SetColor(ByVal New_ColorName As String)
Dim i As Integer
iColor = -1
For i = 0 To 26
If New_ColorName = SysColorNames(i) Then
iColor = i
Exit For
End If
Next i
If iColor = -1 Then iColor = MyColor
CurHighLight = iColor
SelColor = SysColors(iColor)
SelColorName = SysColorNames(iColor)
'draw palette
DrawSysPal CurTop
End Sub
Public Property Get SelectedColor() As Long
SelectedColor = SelColor
End Property
Public Property Get SelectedColorName() As String
Attribute SelectedColorName.VB_Description = "Returns the selected colors name."
SelectedColorName = SelColorName
End Property
Public Property Get BackColor() As OLE_COLOR
BackColor = MyBackColor
End Property
Public Property Let BackColor(ByVal New_BackColor As OLE_COLOR)
MyBackColor = New_BackColor
PropertyChanged "BackColor"
End Property
Public Property Get ForeColor() As OLE_COLOR
ForeColor = MyForeColor
End Property
Public Property Let ForeColor(ByVal New_ForeColor As OLE_COLOR)
MyForeColor = New_ForeColor
PropertyChanged "ForeColor"
End Property
Public Property Get ClickType() As ClickTypes
Attribute ClickType.VB_Description = "Specifies single or double click for selection."
ClickType = MyClickType
End Property
Public Property Let ClickType(ByVal New_ClickType As ClickTypes)
MyClickType = New_ClickType
PropertyChanged "ClickType"
End Property
Public Property Get DefaultColor() As SystemColors
DefaultColor = MyColor
End Property
Public Property Let DefaultColor(ByVal New_Color As SystemColors)
MyColor = New_Color
PropertyChanged "DefaultColor"
End Property
Private Sub GetColorValues()
'assign system color names
SysColorNames(0) = "3DDKShadow"
SysColorNames(1) = "3DFace"
SysColorNames(2) = "3DHighlight"
SysColorNames(3) = "3DLight"
SysColorNames(4) = "3DShadow"
SysColorNames(5) = "ActiveBorder"
SysColorNames(6) = "ActiveTitleBar"
SysColorNames(7) = "ApplicationWorkspace"
SysColorNames(8) = "ButtonFace"
SysColorNames(9) = "ButtonShadow"
SysColorNames(10) = "ButtonText"
SysColorNames(11) = "Desktop"
SysColorNames(12) = "GrayText"
SysColorNames(13) = "Highlight"
SysColorNames(14) = "HighlightText"
SysColorNames(15) = "InactiveBorder"
SysColorNames(16) = "InactiveCaptionText"
SysColorNames(17) = "InactiveTitleBar"
SysColorNames(18) = "InfoBackground"
SysColorNames(19) = "InfoText"
SysColorNames(20) = "MenuBar"
SysColorNames(21) = "MenuText"
SysColorNames(22) = "ScrollBars"
SysColorNames(23) = "TitleBarText"
SysColorNames(24) = "WindowBackground"
SysColorNames(25) = "WindowFrame"
SysColorNames(26) = "WindowText"
'assign system color values
SysColors(0) = vb3DDKShadow
SysColors(1) = vb3DFace
SysColors(2) = vb3DHighlight
SysColors(3) = vb3DLight
SysColors(4) = vb3DShadow
SysColors(5) = vbActiveBorder
SysColors(6) = vbActiveTitleBar
SysColors(7) = vbApplicationWorkspace
SysColors(8) = vbButtonFace
SysColors(9) = vbButtonShadow
SysColors(10) = vbButtonText
SysColors(11) = vbDesktop
SysColors(12) = vbGrayText
SysColors(13) = vbHighlight
SysColors(14) = vbHighlightText
SysColors(15) = vbInactiveBorder
SysColors(16) = vbInactiveCaptionText
SysColors(17) = vbInactiveTitleBar
SysColors(18) = vbInfoBackground
SysColors(19) = vbInfoText
SysColors(20) = vbMenuBar
SysColors(21) = vbMenuText
SysColors(22) = vbScrollBars
SysColors(23) = vbTitleBarText
SysColors(24) = vbWindowBackground
SysColors(25) = vbWindowFrame
SysColors(26) = vbWindowText
End Sub